package com.wc.alorithm_blue_bridge._DFS._14的方案数;

import java.util.LinkedList;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/4/12 19:28
 * @description https://www.lanqiao.cn/problems/3647/learning/?page=1&first_category_id=1
 */
public class Main {
    static char[] s = new char[15];
    static int[] num = new int[15];
    static char[] op = new char[]{'*', '/', '+', '-'};
    static int len = 0;
    static long res = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n > 0) {
            num[++len] = n % 10;
            n /= 10;
        }
        for (int i = 1, j = len; i < j; i++, j--) {
            int tmp = num[i];
            num[i] = num[j];
            num[j] = tmp;
        }
        dfs(1);
        System.out.println(res);
    }

    static void dfs(int u) {
        if (u == len) {
            int c = cal();
            if (c == 14) res++;
            return;
        }

        for (int i = 0; i < 4; i++) {
            s[u] = op[i];
            dfs(u + 1);
        }
    }

    static int cal() {
        // 装数字
        LinkedList<Integer> nums = new LinkedList<>();
        // 装符号
        LinkedList<Character> ops = new LinkedList<>();
        nums.add(num[1]);
        for (int i = 1; i < len; i++) {
            if (s[i] == '*' || s[i] == '/') {
                int a = nums.removeLast();
                int b = num[i + 1];
                if (s[i] == '*') {
                    nums.add(a * b);
                } else {
                    if (b == 0) return -1;
                    nums.add(a / b);
                }
            } else {
                nums.add(num[i + 1]);
                ops.add(s[i]);
            }
        }
        while (nums.size() >= 2) {
            int a = nums.removeFirst();
            int b = nums.removeFirst();
            char op = ops.removeFirst();
            if (op == '+') {
                nums.addFirst(a + b);
            } else {
                nums.addFirst(a - b);
            }
        }
        return nums.getFirst();
    }
}
